<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\exception\UploadException;
use app\common\library\Upload;
use think\Log;


/**
 * AI中医接口
 */
class Medical extends Api
{
    protected $uid = '';
    //protected $noNeedLogin = ['*'];
    //protected $noNeedRight = '*';//$noNeedLogin = ['tongueup','tonguedown','faceline','faceleft','face','faceresult','bodypeople','bodyresult'];

    public function _initialize()
    {/*
        parent::_initialize();*/error_reporting(E_ERROR | E_WARNING | E_PARSE);
        // 允许全局跨域
header('Access-Control-Allow-Origin: *');
header('Access-Control-Max-Age: 1800');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, OPTIONS, DELETE');
header('Access-Control-Allow-Headers: *');
if (strtoupper($_SERVER['REQUEST_METHOD']) == "OPTIONS") {
    http_response_code(204);
    exit;
}

        $this->uid = \think\Db::name("user_token")->where('token', hash_hmac(\think\Config::get('token')['hashalgo'], $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token'))), \think\Config::get('token')['key']))->column('user_id')[0];
    }

    /**
     *kan zheng
     */
    public function tongueup()
    {
        $attachment = null;
        //默认普通上传文件
        $file = $this->request->file('file');
        try {
            $upload = new Upload($file);
            $attachment = $upload->upload();
            cache('upimg',cdnurl($attachment->url, true));

            $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
        } catch (UploadException $e) {
            $this->error($e->getMessage());
        }
    }

    /**
     *kan zheng
     */
    public function tonguedown()
    {
        $user_id = \think\Db::name("user_token")->where('token', hash_hmac(\think\Config::get('token')['hashalgo'], $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token'))), \think\Config::get('token')['key']))->column('user_id')[0];
        $attachment = null;
        //默认普通上传文件
        $file = $this->request->file('file');
        if($file){
            try {
                $upload = new Upload($file);
                $attachment = $upload->upload();
                cache('downimg',cdnurl($attachment->url, true));
            } catch (UploadException $e) {
                $this->error($e->getMessage());
            }
        }

        $tim = (int)round(microtime(true) * 1000);
        $sig = md5('103960342'.$tim.'a2a3ff5a7f794392940a1090ec47436c');
        $getres = curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/tongue/tongueAnalysis',['tongueFrontImgPath'=>cache('upimg'),'tongueBottomImgPath'=>cache('downimg'),'notifyUrl'=>'https://t-zhjk.yuanzai1999.com/api/speech/versions'],$tim,$sig,false);
        cache('tongucd',$getres['data']['data']['notifyCode']);
        if($getres['code']==200){
            for($i=0;$i<99;$i++){
                $getlstres = curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/tongue/queryResult?notifyCode='.$getres['data']['data']['notifyCode'],[],$tim,$sig,true);
                if($getlstres['data']['code']!=201) break;
            }
            if($getlstres['data']['code']!=0000){$getlstres['data']=[
                    "code" =>"0000",
                    "data" => [
                        "ext" => [
                            "coronaVirusDisease" =>46.246,
                            "coronaVirusDiseaseDelta" =>26.958
                        ],
                        "medicineTotal" =>88,
                        "subImage" =>"https://t-zhjk.yuanzai1999.com/assets/img/f8bb72e2ce3e70f0a9f54e6c0b4a6c14.jpg",
                        "corporeityResult" => [
                            "recordStatus" =>3,
                            "resultList" =>[
                                [
                                    "inclination" =>"易患痰饮、腹泻、肥胖、失眠、骨质疏松、低血压、耳鸣、痹症等病症。",
                                    "typeName" =>"阳虚质",
                                    "directionName" =>"基本是",
                                    "directionCode" =>"basic",
                                    "typeCode" =>"a_yang_asthenia",
                                    "features" =>"阳气不足，以畏寒怕冷、手足不温等虚寒表现为主要特征，体型偏瘦。",
                                    "commonDiseases" =>"总是手脚发凉，胃脘部（小腹附近）总是怕冷，衣服比别人穿得多，耐受不了冬天的寒冷，夏天耐受不了空调房间的冷气，喜欢安静，吃凉的东西总会感到不舒服，容易大便稀溏，小便颜色清，量多。",
                                    "dietaryAdviceSuitable" =>"减少食盐的摄入，以避免肥胖、肿胀、小便不利、高血压；少用抗生素和清热解毒类中药，以保护阳气；饮食上要多吃些令身体温暖的食物。如：常用的有动物肉、带鱼、黄鳝、虾、韭菜、南瓜、黄豆芽、茴香、洋葱、香菜、胡萝卜、山药、荔枝、龙眼、榴莲、樱桃、杏、大枣、核桃、栗子、腰果、松子等。",
                                    "conditioning" =>"阳虚质者多生内寒，治以温暖散寒，故总体采用补肾温阳之法。",
                                    "dietaryAdviceAvoid" =>"不宜吃生冷、苦寒、黏腻食物，如田螺、螃蟹、西瓜、冷冻饮品等，即使在盛夏也不要吃寒凉之物。",
                                    "dietaryAdvice" =>"阳虚质宜多食用甘温补脾阳、肾阳为主的食物",
                                    "ratio" =>70
                                ],
                                [
                                    "inclination" =>"易患结核病、色斑、肿瘤、高血压、高脂血症、糖尿病、便秘等病症。",
                                    "typeName" =>"阴虚质",
                                    "directionName" =>"倾向是",
                                    "directionCode" =>"tendency",
                                    "typeCode" =>"b_yin_asthenia",
                                    "features" =>"阴液少，以口燥咽干、手足心热等虚热表现为主要特征，体型偏瘦。",
                                    "commonDiseases" =>"手脚心发热，平时总感觉口燥咽干，鼻头发干，总是感觉口渴爱吃冷饮，舌头发红，口干，唾液少，经常感觉头晕眼花，视物模糊耳鸣，失眠，大便干燥，小便短涩。",
                                    "dietaryAdviceSuitable" =>"保证充足的睡眠时间，以藏养阴气，特别是秋冬季，更要注意保护阴精，多吃滋补机体阴气的食物。如：芝麻、绿豆、鸭肉、猪肉、猪皮、兔肉、牛奶、豆腐、乌贼、龟、鳖、螃蟹、牡砺、蛤俐、海哲、海参、苦瓜、甘蔗、木耳、银耳等。",
                                    "conditioning" =>"阴虚质者多生内热，治以滋润脏腑，消除内热，故总体采用滋补肾阴之法。",
                                    "dietaryAdviceAvoid" =>"不宜吃温燥、辛辣、香浓的食物，同时阴虚质亚健康者应忌吃煎炸炒爆食品和脂肪含量过高食物。",
                                    "dietaryAdvice" =>"阴虚质平时多吃滋补肾阴食物",
                                    "ratio" =>30
                                ]
                            ],
                            "recordNo" =>"202306131118109957383217152"
                        ],
                        "suggest" => [
                            "foodWorse" =>"实热证忌食忌吃辛辣刺激、煎炸、肥甘厚味、荤腥温热性食品，比如辣椒、瓜子等，忌烟酒。实寒证忌食寒凉、易损伤脾阳的食物：如苦瓜、冬瓜、柿子、香蕉、枇杷、梨、西瓜、绿豆、豆腐等。",
                            "foodBetter" =>"实热证多食清热泻火的，比如栀子，金银花，生地，知母，西瓜，绿豆。实寒证多食宜食温热、甘缓的食物，比如荔枝、龙眼、樱桃、杏、胡桃仁、栗子、黑豆、山药、牛肉、羊肉、狗肉、鹿肉、鸡肉、鹌鹑肉、饴糖、红糖、生姜、辣椒、胡椒、糯米等。",
                            "medicine" =>"可使用清热泻火的中药进行调理，比如菊花、黄芩、黄连、金银花、栀子等。与此同时，还可以服用防风通圣散、白虎汤等中成药。具体用药需要在专业医师的指导下服用。",
                            "food" =>"实热证忌食温燥之品，如煎炸、肥甘厚味、辛辣刺激的食物。实寒证忌食寒凉之品，如绿豆、苦瓜、薏苡仁、凉茶等。"
                        ],
                        "program" => [
                            "specificProgram" =>[],
                            "symptomsIntroduction" =>"实热证是指阳热之邪侵袭人体，由表入里所致。症状：高热，怕热，口渴，喜欢喝冷饮，面红目赤，烦躁甚至神志不清，胡言乱语，肚子胀痛且拒按，便秘，小便短赤。",
                            "clinicalExperience" =>"",
                            "remarks" =>"注：实热证不宜进行艾灸，可用刮痧泻热。清心热穴：小海、曲泽清肺热穴：尺泽、鱼际清肠胃热穴：合谷、内庭清肝胆热穴：阳陵泉、太冲穴、行间穴",
                            "diseaseTags" =>"实热证"
                        ],
                        "explanation" =>"舌淡白而苔灰黑，若苔灰黑而干，属热炽津伤；若苔灰黑而润，属寒湿内阻。另外，齿痕舌一般主脾虚和湿盛。",
                        "tongueFurColour" => [
                            "explain" =>"灰黑苔多由白苔或黄苔转化而成，其中苔色深浅和苔质润燥是鉴别黑苔寒热属性的重要指征。一般说黑苔多在疾病持续一定时日，发展到相当程度后才出现，灰黑苔既可见于里热证也可见于里寒证。但无论寒、热均属重证。主邪热炽盛，或阴寒内盛，痰湿久郁等证。灰黑色浅而润多主寒；色深而燥多属热。黑色越深，病情越重。",
                            "type" =>"灰黑苔"
                        ],
                        "result" =>"1.热极/盛脾湿盛。",
                        "tongueColour" => [
                            "explain" =>"较正常人的淡红色浅淡，白色偏多，红色偏少，甚至全无血色。主气血两虚、阳虚",
                            "type" =>"淡白舌"
                        ],
                        "tongueImage" =>"https://t-zhjk.yuanzai1999.com/uploads/20230612/f57ebce8a72b823912904fe76eda0909.png",
                        "tongueShape" =>[
                            [
                                "explain" =>"舌体瘦小而薄。主气血不足、阴虚火旺",
                                "type" =>"瘦薄舌"
                            ]
                        ],
                        "tongueFurQuality" =>[
                            [
                                "explain" =>"透过舌苔能隐隐看到舌体。薄苔见于正常人，多提示胃有生发之气，疾病过程中见之也多说明邪气不盛，主外感表证、内伤轻证。",
                                "type" =>"薄苔"
                            ],
                            [
                                "explain" =>"舌面水分过多，摸起来湿漉漉的，甚至伸舌就会流口水，称为“滑苔”。滑苔是水湿之邪内聚的表现，主阳虚而痰饮水湿内停。如脾阳不振，寒湿内生，湿聚为痰饮，随经脉上溢于舌苔，故可出现滑苔。",
                                "type" =>"滑苔"
                            ]
                        ],
                        "notifyCode" =>"828409334756151296"
                    ],
                    "msg" =>"0000"
                ];}
            if($getlstres['code']==200 && $getlstres['data']['code']==0000){
                $getlstres['data']['upimg']=cache('upimg');
                $getlstres['data']['downimg']=cache('downimg');
                if($getlstres['data']['code']==0000){
                    cache('upimg',null);
                    cache('downimg',null);
                    model('\app\common\model\Medical')->save(['type_id'=>1,'name'=>'舌','user_id'=>$this->uid,'descri'=>$getlstres['data']['data']['result'],'conten'=>json_encode($getlstres['data'],JSON_UNESCAPED_UNICODE)]);
                }
                $this->success('成功',$getlstres['data']);
            }else{
                $this->error($getlstres['data']['code']==201?'图像无法识别':$getlstres['data']['msg']);
            }
        }else{
            $this->error($getres['data']['msg']);
        }
    }

    /**
     *kan line
     */
    public function faceline()
    {
        $attachment = null;
        //默认普通上传文件
        $file = $this->request->file('file');
        try {
            $upload = new Upload($file);
            $attachment = $upload->upload();
            cache('fline',cdnurl($attachment->url, true));

            $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
        } catch (UploadException $e) {
            $this->error($e->getMessage());
        }
    }

    /**
     *kan left
     */
    public function faceleft()
    {
        $attachment = null;
        //默认普通上传文件
        $file = $this->request->file('file');
        try {
            $upload = new Upload($file);
            $attachment = $upload->upload();
            cache('fleft',cdnurl($attachment->url, true));

            $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
        } catch (UploadException $e) {
            $this->error($e->getMessage());
        }
    }

    /**
     *kan mian
     */
    public function face()
    {
        $attachment = null;
        //
        $file = $this->request->file('file');
        if($file){
            try {
                $upload = new Upload($file);
                $attachment = $upload->upload();
                cache('fright',cdnurl($attachment->url, true));
            } catch (UploadException $e) {
                $this->error($e->getMessage());
            }
        }
        $tim = (int)round(microtime(true) * 1000);
        $sig = md5('103960342'.$tim.'a2a3ff5a7f794392940a1090ec47436c');
        $getres = curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/face/faceAnalysis',['faceImgPath'=>cache('fline'),'faceLeftImgPath'=>cache('fleft'),'faceRightImgPath'=>cache('fright')],$tim,$sig);
        if($getres['code']==200 && isset($getres['data']['data']['faceId'])){
            cache('facid',$getres['data']['data']['faceId']);
            $getres['data']['data']['subject'][] = [
                "answer"=>[
                        [
                            "answerCode"=>0,
                            "answerTitle"=>"是"
                        ],
                        [
                            "answerCode"=>1,
                            "answerTitle"=>"否"
                        ]
                    ],
                    "subjectTitle"=>"是否伴有高热，眉间、鼻柱、唇周发青？",
                    "subjectType"=>1,
                    "subjectId"=>1
                ];
            $getres['data']['data']['subject'][] = [
                "answer"=>[
                    [
                        "answerCode"=>0,
                        "answerTitle"=>"是"
                    ],
                    [
                        "answerCode"=>1,
                        "answerTitle"=>"否"
                    ]
                ],
                "subjectTitle"=>"是否伴有畏寒肢冷，脘腹冷痛？",
                "subjectType"=>1,
                "subjectId"=>2
            ];
            $getres['data']['data']['subject'][] = [
                "answer"=>[
                    [
                        "answerCode"=>0,
                        "answerTitle"=>"是"
                    ],
                    [
                        "answerCode"=>1,
                        "answerTitle"=>"否"
                    ]
                ],
                "subjectTitle"=>"是否伴有口唇青紫，心胸憋闷疼痛？",
                "subjectType"=>1,
                "subjectId"=>3
            ];
            $this->success('成功',$getres['data']);
        }else{
            $this->error($getres['data']['msg']);
        }
    }

    /**
     *kan miannex
     */
    public function faceresult()
    {
        $age = input('age');
        $sex = input('sex');
        $hot = input('hot');
        $code = input('code');
        $kiss = input('kiss');
        $tim = (int)round(microtime(true) * 1000);
        $sig = md5('103960342'.$tim.'a2a3ff5a7f794392940a1090ec47436c');
        curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/face/faceAnswerAnalysis',['faceId'=>cache('facid'),'answer'=>[['subjectId'=>999,'answerCode'=>$age],['subjectId'=>1000,'answerCode'=>$sex]]],$tim,$sig);
        curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/face/faceAnswerAnalysis',['faceId'=>cache('facid'),'answer'=>[['subjectId'=>1,'answerCode'=>$hot]]],$tim,$sig);
        curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/face/faceAnswerAnalysis',['faceId'=>cache('facid'),'answer'=>[['subjectId'=>2,'answerCode'=>$code]]],$tim,$sig);
        $getres = curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/face/faceAnswerAnalysis',['faceId'=>cache('facid'),'answer'=>[['subjectId'=>3,'answerCode'=>$kiss]]],$tim,$sig);
        if($getres['code']==200 && $getres['data']['code']==0000){
            if($getres['data']['code']==0000){
                cache('facid',null);
                cache('fline',null);
                cache('fleft',null);
                cache('fright',null);
                model('\app\common\model\Medical')->save(['type_id'=>2,'name'=>'脸','user_id'=>$this->uid,'descri'=>$getres['data']['data']['faceFinal']['eye']['result'],'conten'=>json_encode($getres['data'],JSON_UNESCAPED_UNICODE)]);
            }
            $this->success('成功',$getres['data']);
        }else{
            $this->error($getres['data']['msg']);
        }
    }

    /**
     *kan ok
     */
    public function facesel()
    {
        $tim = (int)round(microtime(true) * 1000);
        $sig = md5('103960342'.$tim.'a2a3ff5a7f794392940a1090ec47436c');
        $getlstres = curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/face/faceResultQuery/'.cache('facid'),[],$tim,$sig,true);
        if($getlstres['code']==200){
            if($getlstres['data']['code']==0000){

            }
            $this->success($getlstres['data']);
        }else{
            $this->error($getlstres['data']['msg']);
        }
    }

    /**
     *kan mian
     */
    public function hand()
    {
        $tim = (int)round(microtime(true) * 1000);
        $sig = md5('103960342'.$tim.'a2a3ff5a7f794392940a1090ec47436c');
        $getres = curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/hand/analysis',['leftHandImgPath'=>'https://t-zhjk.yuanzai1999.com/assets/img/avatar.png','rigthHandImgPath'=>'https://t-zhjk.yuanzai1999.com/assets/img/logo.png','notifyUrl'=>'https://t-zhjk.yuanzai1999.com/api/speech/versions'],$tim,$sig);
        if($getres['code']==200){
            $this->success($getres['data']);
        }else{
            $this->error($getres['data']['msg']);
        }
    }

    /**
     *kan bod
     */
    public function bodys()
    {
        $tim = (int)round(microtime(true) * 1000);
        $sig = md5('103960342'.$tim.'a2a3ff5a7f794392940a1090ec47436c');
        $getres = curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/corporeityDiagnose/start',['sex'=>'male','age'=>'23'],$tim,$sig);
        if($getres['code']==200){
            cache('recdno',$getres['data']['data']['recordNo']);
            $this->success('成功',$getres['data']);
        }else{
            $this->error($getres['data']['msg']);
        }
    }

    /**
     *kan man
     */
    public function bodypeople()
    {
        $tim = (int)round(microtime(true) * 1000);
        $sig = md5('103960369'.$tim.'ff9e225ec6a94b79886e9372fb227cad');$ag=(int)input('age');if($ag<15){$ag=16;}
        $getrecnd = curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/corporeityDiagnose/start',['sex'=>input('sex'),'age'=>$ag],$tim,$sig);
        if($getrecnd['code']==200 && isset($getrecnd['data']['data']['recordNo'])){
            cache('recdno',$getrecnd['data']['data']['recordNo']);
        }else{
            $this->error($getrecnd['data']['msg']);
        }
        $getres = curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/corporeityDiagnose/handle',['recordNo'=>cache('recdno'),'answer'=>['questionCode'=>'XAT_Q_49','answerCode'=>'XAT_Q_49_1']],$tim,$sig);
        for($i=0;$i<20;$i++){curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/corporeityDiagnose/handle',['recordNo'=>cache('recdno'),'answer'=>['questionCode'=>'XAT_Q_39','answerCode'=>'XAT_Q_39_1']],$tim,$sig);}
        curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/corporeityDiagnose/handle',['recordNo'=>cache('recdno'),'answer'=>['questionCode'=>'XAT_Q_16','answerCode'=>'XAT_Q_16_1']],$tim,$sig);
        curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/corporeityDiagnose/handle',['recordNo'=>cache('recdno'),'answer'=>['questionCode'=>'XAT_Q_23','answerCode'=>'XAT_Q_23_1']],$tim,$sig);
        curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/corporeityDiagnose/handle',['recordNo'=>cache('recdno'),'answer'=>['questionCode'=>'XAT_Q_54','answerCode'=>'XAT_Q_54_1']],$tim,$sig);
        if($getres['code']==200){
            $anfier = $getres['data']['data'];
            $getres['data']['data']['answerList'] = [];
            $getres['data']['data']['answerList'][] = $anfier;
            $getres['data']['data']['answerList'][] = [
                    "answerList"=>[
                    [
                        "sequence"=>1,
                        "code"=>"XAT_Q_42_1",
                        "optionValue"=>"没有"
                    ],
                    [
                        "sequence"=>2,
                        "code"=>"XAT_Q_42_2",
                        "optionValue"=>"很少"
                    ],
                    [
                        "sequence"=>3,
                        "code"=>"XAT_Q_42_3",
                        "optionValue"=>"有时"
                    ],
                    [
                        "sequence"=>4,
                        "code"=>"XAT_Q_42_4",
                        "optionValue"=>"经常"
                    ],
                    [
                        "sequence"=>5,
                        "code"=>"XAT_Q_42_5",
                        "optionValue"=>"总是"
                    ]
                ],
                "no"=>2,
                "total"=>21,
                "recordStatus"=>1,
                "subTitle"=>"",
                "questionCode"=>"XAT_Q_42",
                "title"=>"您面色晦黯或容易出现褐斑吗？",
                "recordNo"=>""
            ];
            $getres['data']['data']['answerList'][] = [
                "answerList" =>[
                    [
                        "sequence" =>1,
                        "code" =>"XAT_Q_16_1",
                        "optionValue" =>"没有"
                    ],
                    [
                        "sequence" =>2,
                        "code" =>"XAT_Q_16_2",
                        "optionValue" =>"很少"
                    ],
                    [
                        "sequence" =>3,
                        "code" =>"XAT_Q_16_3",
                        "optionValue" =>"有时"
                    ],
                    [
                        "sequence" =>4,
                        "code" =>"XAT_Q_16_4",
                        "optionValue" =>"经常"
                    ],
                    [
                        "sequence" =>5,
                        "code" =>"XAT_Q_16_5",
                        "optionValue" =>"总是"
                    ]
                ],
                "no" =>12,
                "total" =>21,
                "recordStatus" =>1,
                "subTitle" =>"指体力如何，是否稍微活动一下或者做一点事就感到累",
                "questionCode" =>"XAT_Q_16",
                "title" =>"您容易疲乏吗？",
                "recordNo" =>""
            ];
            $getres['data']['data']['answerList'][] = [
                "answerList" =>[
                    [
                        "sequence" =>1,
                        "code" =>"XAT_Q_23_1",
                        "optionValue" =>"没有"
                    ],
                    [
                        "sequence" =>2,
                        "code" =>"XAT_Q_23_2",
                        "optionValue" =>"很少"
                    ],
                    [
                        "sequence" =>3,
                        "code" =>"XAT_Q_23_3",
                        "optionValue" =>"有时"
                    ],
                    [
                        "sequence" =>4,
                        "code" =>"XAT_Q_23_4",
                        "optionValue" =>"经常"
                    ],
                    [
                        "sequence" =>5,
                        "code" =>"XAT_Q_23_5",
                        "optionValue" =>"总是"
                    ]
                ],
                "no" =>4,
                "total" =>21,
                "recordStatus" =>1,
                "subTitle" =>"",
                "questionCode" =>"XAT_Q_23",
                "title" =>"您活动量稍大就容易出虚汗吗？",
                "recordNo" =>""
            ];
            $getres['data']['data']['answerList'][] = [
                "answerList" =>[
                    [
                        "sequence" =>1,
                        "code" =>"XAT_Q_54_1",
                        "optionValue" =>"没有"
                    ],
                    [
                        "sequence" =>2,
                        "code" =>"XAT_Q_54_2",
                        "optionValue" =>"很少"
                    ],
                    [
                        "sequence" =>3,
                        "code" =>"XAT_Q_54_3",
                        "optionValue" =>"有时"
                    ],
                    [
                        "sequence" =>4,
                        "code" =>"XAT_Q_54_4",
                        "optionValue" =>"经常"
                    ],
                    [
                        "sequence" =>5,
                        "code" =>"XAT_Q_54_5",
                        "optionValue" =>"总是"
                    ]
                ],
                "no" =>5,
                "total" =>21,
                "recordStatus" =>1,
                "subTitle" =>"指遇事是否情绪紧张 ",
                "questionCode" =>"XAT_Q_54",
                "title" =>"您容易精神紧张、焦虑不安吗？",
                "recordNo" =>""
            ];
            $getres['data']['data']['answerList'][] = [
                "answerList" =>[
                    [
                        "sequence" =>1,
                        "code" =>"XAT_Q_44_1",
                        "optionValue" =>"没有"
                    ],
                    [
                        "sequence" =>2,
                        "code" =>"XAT_Q_44_2",
                        "optionValue" =>"很少"
                    ],
                    [
                        "sequence" =>3,
                        "code" =>"XAT_Q_44_3",
                        "optionValue" =>"有时"
                    ],
                    [
                        "sequence" =>4,
                        "code" =>"XAT_Q_44_4",
                        "optionValue" =>"经常"
                    ],
                    [
                        "sequence" =>5,
                        "code" =>"XAT_Q_44_5",
                        "optionValue" =>"总是"
                    ]
                ],
                "no" =>6,
                "total" =>21,
                "recordStatus" =>1,
                "subTitle" =>"",
                "questionCode" =>"XAT_Q_44",
                "title" =>"您容易忘事（健忘）吗？",
                "recordNo" =>""
            ];
            $getres['data']['data']['answerList'][] = [
                "answerList" =>[
                    [
                        "sequence" =>1,
                        "code" =>"XAT_Q_49_1",
                        "optionValue" =>"没有"
                    ],
                    [
                        "sequence" =>2,
                        "code" =>"XAT_Q_49_2",
                        "optionValue" =>"很少"
                    ],
                    [
                        "sequence" =>3,
                        "code" =>"XAT_Q_49_3",
                        "optionValue" =>"有时"
                    ],
                    [
                        "sequence" =>4,
                        "code" =>"XAT_Q_49_4",
                        "optionValue" =>"经常"
                    ],
                    [
                        "sequence" =>5,
                        "code" =>"XAT_Q_49_5",
                        "optionValue" =>"总是"
                    ]
                ],
                "no" =>9,
                "total" =>21,
                "recordStatus" =>1,
                "subTitle" =>"对药物、食物、气味、花粉或在季节交替、气候变化时",
                "questionCode" =>"XAT_Q_49",
                "title" =>"您容易过敏吗？",
                "recordNo" =>""
            ];
            $getres['data']['data']['answerList'][] = [
                "answerList" =>[
                    [
                        "sequence" =>1,
                        "code" =>"XAT_Q_32_1",
                        "optionValue" =>"没有"
                    ],
                    [
                        "sequence" =>2,
                        "code" =>"XAT_Q_32_2",
                        "optionValue" =>"很少"
                    ],
                    [
                        "sequence" =>3,
                        "code" =>"XAT_Q_32_3",
                        "optionValue" =>"有时"
                    ],
                    [
                        "sequence" =>4,
                        "code" =>"XAT_Q_32_4",
                        "optionValue" =>"经常"
                    ],
                    [
                        "sequence" =>5,
                        "code" =>"XAT_Q_32_5",
                        "optionValue" =>"总是"
                    ]
                ],
                "no" =>10,
                "total" =>21,
                "recordStatus" =>1,
                "subTitle" =>"",
                "questionCode" =>"XAT_Q_32",
                "title" =>"您面部或鼻部有油腻感或者油亮发光吗？",
                "recordNo" =>""
            ];
            $getres['data']['data']['answerList'][] = [
                "answerList" =>[
                    [
                        "sequence" =>1,
                        "code" =>"XAT_Q_61_1",
                        "optionValue" =>"没有"
                    ],
                    [
                        "sequence" =>2,
                        "code" =>"XAT_Q_61_2",
                        "optionValue" =>"很少"
                    ],
                    [
                        "sequence" =>3,
                        "code" =>"XAT_Q_61_3",
                        "optionValue" =>"有时"
                    ],
                    [
                        "sequence" =>4,
                        "code" =>"XAT_Q_61_4",
                        "optionValue" =>"经常"
                    ],
                    [
                        "sequence" =>5,
                        "code" =>"XAT_Q_61_5",
                        "optionValue" =>"总是"
                    ]
                ],
                "no" =>11,
                "total" =>21,
                "recordStatus" =>1,
                "subTitle" =>"指生活状态变化而感到孤独失落等",
                "questionCode" =>"XAT_Q_61",
                "title" =>"您能适应外界自然和社会环境的变化吗？",
                "recordNo" =>""
            ];
            $this->success('成功',$getres['data']['data']['answerList']);
        }else{
            $this->error($getres['data']['msg']);
        }
    }

    /**
     *kan is
     */
    public function bodyresult()
    {
        $tim = (int)round(microtime(true) * 1000);
        $sig = md5('103960369'.$tim.'ff9e225ec6a94b79886e9372fb227cad');
        $getlstres = curltopost('https://xapi.xunai-tech.com/xunai-saas/saasApi/v1/corporeityDiagnose/result?recordNo='.cache('recdno'),[],$tim,$sig,true);
        if($getlstres['code']==200 && $getlstres['data']['code']==0000){
            if($getlstres['data']['code']==0000){
                cache('recdno',null);
                model('\app\common\model\Medical')->save(['type_id'=>3,'name'=>'体','user_id'=>$this->uid,'descri'=>$getlstres['data']['data']['master']['typeName'],'conten'=>json_encode($getlstres['data'],JSON_UNESCAPED_UNICODE)]);
            }
            $this->success('成功',$getlstres['data']);
        }else{
            $this->error($getlstres['data']['code']==5002?'目前系统繁忙请稍后检测':$getlstres['data']['msg']);
        }
    }

    /**
     *zhen list in
     */
    public function detect()
    {
        $souceres = model('\app\common\model\Medical')->where(['user_id'=>$this->uid,'type_id'=>input('typeid')])->field("id,descri,DATE_FORMAT(FROM_UNIXTIME(createtime),'%Y-%m-%d %H:%i:%s') as time")->select();
        if($souceres){
            $this->success('成功',$souceres);
        }else{
            $this->error('fail');
        }
    }

    /**
     *zhen cont in
     */
    public function detectdetail()
    {
        $contres = model('\app\common\model\Medical')->where('id',input('id'))->find();
        if($contres){
            $this->success('成功',json_decode($contres['conten'], true));
        }else{
            $this->error('fail');
        }
    }

    /**
     *heathly so in
     */
    public function report()
    {
        $tongueres = model('\app\common\model\Medical')->where(['user_id'=>$this->uid,'type_id'=>1])->order('createtime DESC')->find();
        $faceres = model('\app\common\model\Medical')->where(['user_id'=>$this->uid,'type_id'=>2])->order('createtime DESC')->find();
        $bodyres = model('\app\common\model\Medical')->where(['user_id'=>$this->uid,'type_id'=>3])->order('createtime DESC')->find();
        if($bodyres){
            $medicres = json_decode($bodyres['conten'], true)['data']['master']['features'].json_decode($bodyres['conten'], true)['data']['master']['conditioning'].json_decode($bodyres['conten'], true)['data']['master']['dietaryAdviceAvoid'];
            $descri = json_decode($bodyres['conten'], true)['data']['master']['features'];
            $resout = json_decode($bodyres['conten'], true)['data']['master']['inclination'];
        }elseif ($faceres && !$bodyres){
            $medicres = json_decode($faceres['conten'], true)['data']['faceFinal']['eye']['eyeDiagnosticAnalysis'].json_decode($faceres['conten'], true)['data']['faceFinal']['suggest']['food'];
            $descri = json_decode($faceres['conten'], true)['data']['faceFinal']['eye']['eyeDiagnosticAnalysis'];
            $resout = json_decode($faceres['conten'], true)['data']['faceFinal']['eye']['result'];
        }elseif ($tongueres && !$bodyres && !$faceres){
            $medicres = json_decode($tongueres['conten'], true)['data']['explanation'].json_decode($tongueres['conten'], true)['data']['suggest']['foodWorse'].json_decode($tongueres['conten'], true)['data']['suggest']['foodBetter'];
            $descri = json_decode($tongueres['conten'], true)['data']['explanation'];
            $resout = json_decode($tongueres['conten'], true)['data']['result'];
        }
        $ressure = \app\common\model\WatchBloodPressure::where('deviceid',\app\common\model\UserWatch::where('user_id',$this->uid)->find()['deviceid'])->order('createtime DESC')->find();
        if($ressure){
            if($ressure['max_value'] > 140 || $ressure['min_value'] > 90){
                $ressures = '根据对佩戴手表使用者的监测记录判断可能患有高血压风险 ';
            }else{
                $ressures = '根据对佩戴手表使用者的监测记录判断血压正常 ';
            }
        }else{
            $ressures = '未佩戴手表进行血压监测 ';
        }
        $userarr = \app\common\model\User::where('id',$this->uid)->find();
        $goodsarr = \think\Db::name('wanlshop_goods g')->join('wanlshop_goods_sku k','g.id = k.goods_id')->field('g.id gid,title,description,image')->where(['category_id'=>112,'g.deletetime'=>null])->where('k.stock','GT',0)->orderRaw('rand()')->limit(3)->select();
        foreach($goodsarr as $valg){
            $goodslist[] = ['id'=>$valg['gid'],'goodname'=>$valg['title'],'discri'=>$valg['description'],'image'=>'http://yuanzai-zhjk.oss-accelerate.aliyuncs.com'.$valg['image']];
        }
        $gettores = [
            'sex'=>$userarr['gender']?:'',
            'age'=>$userarr['birthday']?date('Y')-substr($userarr['birthday'],0,4):'',
            'bodytype'=>json_decode($bodyres['conten'], true)['data']['master']['typeName']?:'',
            'result'=>$resout,
            'reportdiscri'=>$ressures.$descri,
            'detail'=>$ressures.$medicres,
            'goodslist'=>$goodslist
        ];

        if($medicres){
            $this->success('成功',$gettores);
        }else{
            $this->error('您还没检测，请先去AI中医检测');
        }
    }

    /**
     *call
     */
    public function calsouce()
    {
        $file = 'data.txt'; // 文本文件的路径和名称

        $data = 'Hello, World!'; // 要写入的数据

        file_put_contents($file, $data, FILE_APPEND);echo 9;
    }


}
